package Frame.shopSet;

import FCRendering.FCRBattleOrderConstant;
import FCRendering.FCRMaster;
import FCRendering.sw.FCRValues;
import Frame.entity.UnifyShopSayUIEntity;
import VWorldGameStudio.FCPlayerInfo;
import VWorldGameStudio.touzi.FCTouZiProject;
import socket.FCRSocketClient;
import socket.FCRSocketServer;

import java.util.ArrayList;
import java.util.List;

import static FCRendering.FCRMaster.*;

//投资
public class FunctionTouZiShop extends AShopFuntion {

    FCTouZiProject touZiProject;

    public FunctionTouZiShop(String touZiName) {
        for (FCTouZiProject project : gameSave.getTouZiProjects()) {
            if (project.projectEnName.equals(touZiName)) {
                touZiProject = project;
                break;
            }
        }
        if(touZiProject == null){
            fcv.getMessage().add("找不到该类型投资项目 "+touZiName);
            fcv.showMessage();
        }
        buildShopWindow();
    }

    public void buildShopWindow() {
        resetUI();
    }

    private void resetUI() {
        FCRValues.resetUnifySayUIEntity();

        FCRValues.leftWindowUI[0].leftText = touZiProject.projectCHName;
        FCRValues.leftWindowUI[1].rightText = touZiProject.ad;
        FCRValues.leftWindowUI[2].leftText = "已投资: ";
        FCRValues.leftWindowUI[2].rightText = touZiProject.touZiMoney+"G";
        FCRValues.leftWindowUI[3].leftText = "获得收益: ";
        FCRValues.leftWindowUI[3].rightText = touZiProject.allGetShouYiMoney+"G";
        if(gameSave.isCreateCompany()) {
            FCRValues.rightWindowUI[3].rightText = "投资 " + touZiProject.minTouziMoney + "G";
            FCRValues.rightWindowUI[4].rightText = "投资 " + (touZiProject.minTouziMoney * 10) + "G";
            FCRValues.rightWindowUI[5].rightText = "投资 " + (touZiProject.minTouziMoney * 100) + "G";
        }else {
            FCRValues.rightWindowUI[1].leftText = "对不起，您还没有投资项目资格！";
            FCRValues.rightWindowUI[2].leftText = "请申请注册公司主体吧！";
        }
        FCRValues.rightWindowUI[6].rightText = "退出";
    }

    @Override
    public void clickLeftWindow(int i, UnifyShopSayUIEntity entity) {

    }


    @Override
    public void clickRightWindow(int i, UnifyShopSayUIEntity entity) {
        switch (i) {
            case 3:
                if(gameSave.isCreateCompany()) {
                    if(player1.getMoney() >= touZiProject.minTouziMoney){
                        player1.setMoney(player1.getMoney() - touZiProject.minTouziMoney);
                        touZiProject.touZiMoney += touZiProject.minTouziMoney;
                    }
                    if(touZiProject.touZiMoney > 0) {
                        FCRValues.rightWindowUI[0].leftText = "谢谢老板的投资！";
                        FCRValues.rightWindowUI[1].leftText = "我们会努力经营好的！";
                        fcv.setSetAutoSave(true);
                        FCRValues.leftWindowUI[2].leftText = "已投资: ";
                        FCRValues.leftWindowUI[2].rightText = touZiProject.touZiMoney+"G";
                    }
                }
                break;
            case 4:
                if(gameSave.isCreateCompany()) {
                    if(player1.getMoney() >= touZiProject.minTouziMoney*10){
                        player1.setMoney(player1.getMoney() - touZiProject.minTouziMoney*10);
                        touZiProject.touZiMoney += touZiProject.minTouziMoney*10;
                    }
                    if(touZiProject.touZiMoney > 0) {
                        FCRValues.rightWindowUI[0].leftText = "谢谢老板的投资！";
                        FCRValues.rightWindowUI[1].leftText = "我们会努力经营好的！";
                        fcv.setSetAutoSave(true);
                        FCRValues.leftWindowUI[2].leftText = "已投资: ";
                        FCRValues.leftWindowUI[2].rightText = touZiProject.touZiMoney+"G";
                    }
                }
                break;
            case 5:
                if(gameSave.isCreateCompany()) {
                    if(player1.getMoney() >= touZiProject.minTouziMoney*100){
                        player1.setMoney(player1.getMoney() - touZiProject.minTouziMoney*100);
                        touZiProject.touZiMoney += touZiProject.minTouziMoney*100;
                    }
                    if(touZiProject.touZiMoney > 0) {
                        FCRValues.rightWindowUI[0].leftText = "谢谢老板的投资！";
                        FCRValues.rightWindowUI[1].leftText = "我们会努力经营好的！";
                        fcv.setSetAutoSave(true);
                        FCRValues.leftWindowUI[2].leftText = "已投资: ";
                        FCRValues.leftWindowUI[2].rightText = touZiProject.touZiMoney+"G";
                    }
                }
                break;
            case 6:
                fcv.setOpenSayShop(false);
                FCRMaster.fcv.setOpenSay(false);
                FCRMaster.fcv.setSayNpcName(null);
                FCRMaster.fcv.setSayNpcTextNum(0);
                break;
        }
    }
}
